package com.tanhua.manager;

import com.aliyuncs.exceptions.ClientException;
import com.tanhua.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping(value = "/manage")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/users", name = "分页查询所有用户数据")
    public ResponseEntity findUsersByPage(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10")Integer pagesize) throws ClientException, IOException {
        return userService.findUsersByPage(page,pagesize);
    }


    @GetMapping(value = "/users/{userID}", name = "查询单个用户详情数据")
    public ResponseEntity findUserById(@PathVariable("userID") Long userId) throws ClientException, IOException {
        return userService.findUserById(userId);
    }


    @GetMapping(value = "/videos", name = "查询单个用户视频数据")
    public ResponseEntity findUserVideo(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10")Integer pagesize,
                                          Long uid) throws ClientException, IOException {
        return userService.findUserVideo(page,pagesize,uid);
    }


    @GetMapping(value ="/messages", name = "查询动态数据")
    public ResponseEntity findUserPublish(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10")Integer pagesize,
                                        Long uid,Integer state) throws ClientException, IOException {
        return userService.findUserPublish(page,pagesize,uid,state);
    }


    @GetMapping(value ="/messages/{id}", name = "查询动态数据")
    public ResponseEntity findPublishById(@PathVariable("id") String publishId) throws ClientException, IOException {
        return userService.findPublishById(publishId);
    }

    @GetMapping(value ="/messages/comments", name = "查询动态数据")
    public ResponseEntity findComment(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10")Integer pagesize,
                                      String messageID) throws ClientException, IOException {
        return userService.findComment(page,pagesize,messageID);
    }

}
